using BuildingBlocks.Presentation.Endpoints;
using BuildingBlocks.Presentation.Results;
using Mediator;

namespace Catalog.Api.Features.CatalogItems.GetById;

internal sealed class GetCatalogItemByIdEndpoint : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        app.MapGet($"{Routes.Base}/{{id}}", async (string id, IMediator mediator, CancellationToken cancellationToken) =>
            {
                var result = await mediator.Send(new GetCatalogItemByIdQuery(id), cancellationToken);
                return result.Match(Results.Ok, ApiResponse.Problem);
            })
            .WithName("GetCatalogItemById")
            .WithTags("Catalog");
    }
}
